import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import cookie from 'js-cookie'
// import shopcar from './shopcar'
export default  new Vuex.Store({ 
  // strict: true,
  // modules: {
  state:{
    shopcarNumber:0,
    //是否显示登模块
    ifShowLoginModal:false,
    // 是否显示注册模块
    ifShowRegisterModal:false,
    // 是否header组件的登录状态
    isLogin:cookie.get("pet-token"),
    // isLogin: false,
    // Toast组件显示与隐藏
    toastState: false,
    // toast内容
    toastMsg : '默认内容',
    // toast类型success faile
    toastType:"success",
    //存储用户信息
    userInfo:{
      id:'',
      username:'',
      password:'',
      mobile:'',
      header:''
    },
    // 存储选中的购物车数据
    buyGoodsList:[],
    // 存实付款金额
    totalPrice:'',
    // 搜索的信息
    searchList:[]
    },
  mutations:{
    // 修改登录模块的显示
    showLoginModal(state){
     state.ifShowLoginModal = true;
    },
    // 修改登录模块的隐藏
    hideLoginModal(state){
      state.ifShowLoginModal = false;
    },
    // 修改islogin的值
    changeIsLogin(state){
      state.isLogin =cookie.get('pet-token')
    },
    // 修改toast为显示(内容和类型)
    showToast(state,payload){
      state.toastState = true
      state.toastMsg = payload.msg
      state.toastType = payload.type
    },
    // 修改注册模块的显示
    showRegisterModal(state){
      state.ifShowRegisterModal = true;
     },
     // 修改注册模块的隐藏
     hideRegisterModal(state){
       state.ifShowRegisterModal = false;
     },
    // 修改toast为隐藏
    hideToast(state){
      state.toastState = false
    },
    // 存用户信息用户信息
    setUserInfo(state,data){
      state.userInfo.username = data.username
      state.userInfo.id = data.id
      state.userInfo.password = data.password
      state.userInfo.mobile = data.mobile
      state.userInfo.header= data.header
    },
   
    // 存购物车数量
    setShopcarNumber(state,data){
      state.shopcarNumber= data
    },
    // 存储选中的购物车数据
    setBuyGoodsList(state,data){
      state.buyGoodsList = data
    },
    // 存实付款金额
    setTotalPrice(state,data){
      state.totalPrice = data
    },
    // 存储搜索信息
    setSearchList(state,data){
      state.searchList = data
    },
  },
  actions:{
    // 异步控制显示与隐藏
    changeToastAsync({commit},payload){
      commit("showToast",{
        msg:payload.msg,
        type:payload.type
      });
      setTimeout(()=>{
        commit("hideToast")
      },2000)
    },
    // 存储用户信息
    setUserInfo ({commit},data){
      commit("setUserInfo",data)
    },
  
    setSearchList({ commit }, data){
      commit("setSearchList",data)
    },
    
    // 存购物车数量
    setShopcarNumber({ commit },data){
      commit("setShopcarNumber",data)
    },
     // 存储选中的购物车数据
     setBuyGoodsList({commit},data){
       commit("setBuyGoodsList",data)
     },
     // 存实付款金额
     setTotalPrice({commit},data){
       commit("setTotalPrice",data)
     }
  },
  getters:{
    getIsLogin:(state)=>{
      return state.isLogin
    },
    getUsername:(state)=>{
      return state.userInfo.username
    },
    getPassword:(state)=>{
      return state.userInfo.password
    },
    getHeader:(state)=>{
      return state.userInfo.header
    },
    getMobile:(state)=>{
      return state.userInfo.mobile
    },
    getid:(state)=>{
      return state.userInfo.id
    },
   
    // 获取搜素的信息
    getSearchList:(state)=>{
      return state.searchList
    },
   
    // 获取购物车数量
    getShopcarNumber:(state)=>{
      return state.shopcarNumber
    },
    // 获取选中的购物车数据
    getBuyGoodsList:(state)=>{
      return state.buyGoodsList
    },
    // 存实付款金额
    getTotalPrice:(state)=>{
      return state.totalPrice
    }
  },
//   shopcar
// }
})